#include "data.h"
#include <cstdio>

Data::Data()
{
    strcpy(ppmData.head, "P6\n320 240\n255\n");
//    sprintf(ppmData.head, "P6\n%d %d\n255\n", width, height);
    exchangeDataHeadSize = 0;
    type = RGB;
    validSize = 0;
    memset(sendData, 0, sizeof(sendData));
}

int Data::GetRecvDataHeadSize()
{
    return sizeof(exchangeDataHeadSize);
}

char *Data::GetRecvDataHeadPtr()
{
    return (char *)&exchangeDataHeadSize;
}

int Data::GetPictureDataSize()
{
    return exchangeDataHeadSize;
}

char *Data::GetPictureDataPtr()
{
    return ppmData.data;
}

char *Data::GetSendDataPtr()
{
    return sendData;
}

int Data::GetPPMsize()
{
    return sizeof(ppmData);
}

unsigned char *Data::GetPPMptr()
{
    if(MJPEG == type)
    {
        return (unsigned char*)&(ppmData.data);
    }
    else if(RGB == type)
    {
        return (unsigned char*)&ppmData;
    }

    return (unsigned char*)&(ppmData.data);
}
int Data::getWidth() const
{
    return width;
}

void Data::setWidth(int value)
{
    width = value;
}
int Data::getHeight() const
{
    return height;
}

void Data::setHeight(int value)
{
    height = value;
}

int Data::getValidDataSize() const
{
    return validSize;
}

void Data::setValidDataSize(int size)
{
    validSize = size;
}

void Data::setDirect(DataUtil::Direct dir)
{
    switch (dir) {
    case DataUtil::go:
        sendData[0] = 0x01;
        break;
    case DataUtil::left:
        sendData[0] = 0x02;
        break;
    case DataUtil::right:
        sendData[0] = 0x04;
        break;
    case DataUtil::back:
        sendData[0] = 0x08;
        break;
    case DataUtil::stop:
        sendData[0] = 0x00;
        break;
    default:
        break;
    }
}

int Data::GetSendDataSize()
{
    return sizeof(sendData);
}
